<?php

namespace App\Http\Services;

use App\Http\Model\Hint;
use App\Http\Model\Room;
use App\Http\Model\System;
use App\Http\Model\User;
use App\Http\Model\Lyb;
use App\Http\Services\MsgServices;
use App\Http\Services\RoomMsgServices;

class FullServices extends CommonServices
{
    protected $msgService;
    protected $roomMsgService;
    protected $userModel;
    protected $roomModel;
    protected $systemModel;
    protected $lybModel;

    public function __construct()
    {
        parent::__construct();

        $this->msgService = new MsgServices();
        $this->roomMsgService = new RoomMsgServices();
        $this->userModel = new User();
        $this->roomModel = new Room();
        $this->systemModel = new System();
        $this->lybModel = new Lyb();

    }

    /**
     * 留言板人工审核并发飘萍
     */
    public function lybFullScreen($logId, $b_status, $remind){
        $code = Hint::SUCCESS;
        $msg = '';
        $data = [];
        do {
            if(empty($logId)) {
                break;
            }
            $info = $this->lybModel->getLybEvent($logId);
            if(empty($info)) {
                $code = Hint::PARAM_ERROR;
                break;
            }
            if($info['a_status'] != 1) {
                $code = Hint::PARAM_ERROR;
                $msg = '未进行机审';
                break;
            }
            if($info['show_content'] === '') {
                $code = Hint::PARAM_ERROR;
                $msg = '展示留言内容为空';
                break;
            }
            if($info['b_status'] != 0) {
                $code = Hint::PARAM_ERROR;
                $msg = '人工审已处理不可重复';
                break;
            }
            $this->lybModel->updateLybEventBStatus($logId, $b_status, $remind);

            //发飘屏
            if($b_status == 1) {
                $fullId = 60;
                //自定义活动
                if($info['data_type']==1 && !empty($info['data_id'])) {
                    $lybConfig = $this->lybModel->getCustomLybConfig($info['data_id']);
                    if(!empty($lybConfig)) {
                        $fullId = $lybConfig['full_id'];
                    }
                }

                $fromUserInfo = $this->user->get_user($info['user_id'], true);
                $fromName = empty($fromUserInfo['nickname']) ? '' : $fromUserInfo['nickname'];
                $toUserInfo = $this->user->get_user($info['to_user_id'], true);
                $toName = empty($toUserInfo['nickname']) ? '' : $toUserInfo['nickname'];

                $this->msgService->sendFullScreen($fullId,null,['fromName'=>$fromName, 'toName'=>$toName, 'content'=>$info['show_content']],[]);
            }

        } while (false);

        return compact('code', 'msg', 'data');
    }


}